home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 159_01 / turn.c < prev    next >
C/C++ Source or Header  |  1990-05-15  |  17KB  |  933 lines

  1.  
  2.  /* TURN.C  no mods for V 1.43 
  3.   *
  4.   * Modified all calls of rand() to irand() for Eco-C88 (BW)
  5.   */
  6.  
  7. #include "advent.h"
  8.  
  9.  
  10. /*
  11.         Routine to take 1 turn
  12. */
  13. VOID PASCAL turn(VOID)
  14. {
  15.     auto     SHORT      i;
  16.  
  17.     /* if closing, then he can't leave except via the main office. */
  18.     if (newloc < 9 && newloc != 0 && closing)
  19.     {
  20.     rspeak(130);
  21.     newloc = loc;
  22.     if (!panic)
  23.         clock2 = 15;
  24.     panic = 1;
  25.     }
  26.     /* see if a dwarf has seen him and has come from where he wants to go. */
  27.     if (newloc != loc && !forced(loc) && cond[loc] & NOPIRAT == 0)
  28.     {
  29.     for (i = 1; i < (DWARFMAX - 1); ++i)
  30.         if (odloc[i] == newloc && dseen[i])
  31.         {
  32.         newloc = loc;
  33.         rspeak(2);
  34.         break;
  35.         }
  36.     }
  37.  
  38.     dwarves();
  39.  
  40.     /* on to the regular move. */
  41.     if (loc != newloc)
  42.     {
  43.     ++turns;
  44.     loc = newloc;
  45.     /* check for death */
  46.     if (loc == 0)
  47.     {
  48.         death();
  49.         return;
  50.     }
  51.     /* check for forced move */
  52.     if (forced(loc))
  53.     {
  54.         describe();
  55.         domove();
  56.         return;
  57.     }
  58.     /* check for wandering in dark */
  59.     if (wzdark && dark() && pct(35))
  60.     {
  61.         rspeak(23);
  62.         oldloc2 = loc;
  63.         death();
  64.         return;
  65.     }
  66.     /* describe his situation */
  67.     describe();
  68.     if (!dark())
  69.     {
  70.         ++visited[loc];
  71.         descitem();
  72.     }
  73.     }
  74.     if (closed)
  75.     {
  76.     if (prop[OYSTER] < 0 && toting(OYSTER))
  77.         pspeak(OYSTER, 1);
  78.     for (i = 1; i <= MAXOBJ; ++i)
  79.     {
  80.         if (toting(i) && prop[i] < 0)
  81.         prop[i] = -1 - prop[i];
  82.     }
  83.     }
  84.     wzdark = dark();
  85.     if (knfloc > 0 && knfloc != loc)
  86.     knfloc = 0;
  87.     /* run the timer routine */
  88.     if (stimer())
  89.     return;
  90.     /* ask what he wants to do */
  91.     /* debug */
  92.     if (dbgflg)
  93.     printf("Your current location is %d\n", loc);
  94.     while (!english())
  95.     ;
  96.  
  97.     /* act on his instructions */
  98.     if (motion)
  99.     domove();
  100.     else
  101.     {
  102.     if (object)
  103.         doobj();
  104.     else
  105.         itverb();
  106.     }
  107.  
  108.     return;
  109. }
  110.  
  111. /*
  112.         Routine to describe current location
  113. */
  114. VOID PASCAL describe(VOID)
  115. {
  116.     if (toting(BEAR))
  117.     rspeak(141);
  118.     if (dark())
  119.     rspeak(16);
  120.     else
  121.     {
  122.     if (visited[loc] && brief_sw)
  123.         descsh(loc);
  124.     else
  125.         desclg(loc);
  126.     }
  127.     if (loc == 33 && pct(25) && !closing)
  128.     rspeak(8);
  129.  
  130.     return;
  131. }
  132.  
  133. /*
  134.         Routine to describe visible items
  135. */
  136. VOID PASCAL descitem(VOID)
  137. {
  138.     auto     SHORT      i, state;
  139.  
  140.     for (i = 1; i < MAXOBJ; ++i)
  141.     {
  142.     if (at(i))
  143.     {
  144.         if (i == STEPS && toting(NUGGET))
  145.         continue;
  146.         if (prop[i] < 0)
  147.         {
  148.         if (closed)
  149.             continue;
  150.         else
  151.         {
  152.             prop[i] = 0;
  153.             if (i == RUG || i == CHAIN)
  154.             ++prop[i];
  155.             --tally;
  156.         }
  157.         }
  158.         if (i == STEPS && loc == fixed[STEPS])
  159.         state = 1;
  160.         else
  161.         state = prop[i];
  162.         pspeak(i, state);
  163.     }
  164.     }
  165.     if (tally == tally2 && tally != 0 && limit > 35)
  166.     limit = 35;
  167.  
  168.     return;
  169. }
  170.  
  171. /*
  172.         Routine to handle motion requests
  173. */
  174. VOID PASCAL domove(VOID)
  175. {
  176.     gettrav(loc);
  177.     switch (motion)
  178.     {
  179.     case NULLX:
  180.         break;
  181.     case BACK:
  182.         goback();
  183.         break;
  184.     case LOOK:
  185.         if (detail++ < 3)
  186.         rspeak(15);
  187.         wzdark = 0;
  188.         visited[loc] = 0;
  189.         newloc = loc;
  190.         loc = 0;
  191.         break;
  192.     case CAVE:
  193.         if (loc < 8)
  194.         rspeak(57);
  195.         else
  196.         rspeak(58);
  197.         break;
  198.     default:
  199.         oldloc2 = oldloc;
  200.         oldloc = loc;
  201.         dotrav();
  202.         loc = 0;        /* Modified BW 09/28/85   */
  203.     }
  204.  
  205.     return;
  206. }
  207.  
  208. /*
  209.         Routine to handle request to return
  210.         from whence we came!
  211. */
  212. VOID PASCAL goback(VOID)
  213. {
  214.     auto     SHORT          kk, k2, want, temp;
  215.     auto     TRAV         *pSavTrav;
  216.     auto     SHORT          sSavCnt;
  217.  
  218.     if (forced(oldloc))
  219.     want = oldloc2;
  220.     else
  221.     want = oldloc;
  222.     oldloc2 = oldloc;
  223.     oldloc = loc;
  224.     k2 = 0;
  225.     if (want == loc)
  226.     {
  227.     rspeak(91);
  228.     return;
  229.     }
  230.  
  231.     pSavTrav = pTravel;
  232.     sSavCnt  = sTravCnt;
  233.  
  234.     for (kk = 0; kk < sTravCnt; ++kk)
  235.     {
  236.     if (!pTravel[kk].tcond && pTravel[kk].tdest == want)
  237.     {
  238.         motion = pTravel[kk].tverb;
  239.         dotrav();
  240.         return;
  241.     }
  242.     if (!pTravel[kk].tcond)
  243.     {
  244.         k2     = kk;
  245.         temp = pTravel[kk].tdest;
  246.         gettrav(temp);
  247.         if (forced(temp) && pTravel[0].tdest == want)
  248.         k2 = temp;
  249.         pTravel  = pSavTrav;
  250.         sTravCnt = sSavCnt;
  251.     }
  252.     }
  253.  
  254.     if (k2)
  255.     {
  256.     motion = pTravel[k2].tverb;
  257.     dotrav();
  258.     }
  259.     else
  260.     rspeak(140);
  261.  
  262.     return;
  263. }
  264.  
  265. /*
  266.         Routine to figure out a new location
  267.         given current location and a motion.
  268. */
  269. VOID PASCAL dotrav(VOID)
  270. {
  271.     auto     SHORT     mvflag, hitflag, kk;
  272.     auto     SHORT     rdest, rverb, rcond, robject;
  273.     auto     SHORT     pctt;
  274.  
  275.     newloc = loc;
  276.     mvflag = hitflag = 0;
  277.     pctt   = rand() % 100;
  278.  
  279.     for (kk = 0; kk < sTravCnt && !mvflag; ++kk)
  280.     {
  281.     rdest    = pTravel[kk].tdest;
  282.     rverb    = pTravel[kk].tverb;
  283.     rcond    = pTravel[kk].tcond;
  284.     robject = rcond % 100;
  285.     if (rverb != 1 && rverb != motion && !hitflag)
  286.         continue;
  287.     ++hitflag;
  288.     switch (rcond / 100)
  289.     {
  290.         case 0:
  291.         if (rcond == 0 || pctt < rcond)
  292.             ++mvflag;
  293.         /* debug */
  294.         if (rcond && dbgflg)
  295.             printf("\% move %d %d\n",
  296.                pctt, mvflag);
  297.         break;
  298.         case 1:
  299.         if (robject == 0)
  300.             ++mvflag;
  301.         else
  302.         {
  303.             if (toting(robject))
  304.             ++mvflag;
  305.         }
  306.         break;
  307.         case 2:
  308.         if (toting(robject) || at(robject))
  309.             ++mvflag;
  310.         break;
  311.         case 3:
  312.         case 4:
  313.         case 5:
  314.         case 7:
  315.         if (prop[robject] != (rcond / 100) - 3)
  316.             ++mvflag;
  317.         break;
  318.         default:
  319.         bug(37);
  320.     }
  321.     }
  322.     if (!mvflag)
  323.     badmove();
  324.     else
  325.     {
  326.     if (rdest > 500)
  327.         rspeak(rdest - 500);
  328.     else
  329.     {
  330.         if (rdest > 300)
  331.         spcmove(rdest);
  332.         else
  333.         newloc = rdest;
  334.     }
  335.     }
  336.  
  337.     return;
  338. }
  339.  
  340. /*
  341.         The player tried a poor move option.
  342. */
  343. VOID PASCAL badmove(VOID)
  344. {
  345.     auto     SHORT      msg;
  346.  
  347.     msg = 12;
  348.     if (motion >= 43 && motion <= 50)
  349.     msg = 9;
  350.     if (motion == 29 || motion == 30)
  351.     msg = 9;
  352.     if (motion == 7 || motion == 36 || motion == 37)
  353.     msg = 10;
  354.     if (motion == 11 || motion == 19)
  355.     msg = 11;
  356.     if (verb == FIND || verb == INVENTORY)
  357.     msg = 59;
  358.     if (motion == 62 || motion == 65)
  359.     msg = 42;
  360.     if (motion == 17)
  361.     msg = 80;
  362.     rspeak(msg);
  363.  
  364.     return;
  365. }
  366.  
  367. /*
  368.         Routine to handle very special movement.
  369. */
  370. VOID PASCAL spcmove(SHORT rdest)
  371. {
  372.     switch (rdest - 300)
  373.     {
  374.     case 1:        /* plover movement via alcove */
  375.         if (!holding || (holding == 1 && toting(EMERALD)))
  376.         newloc = (99 + 100) - loc;
  377.         else
  378.         rspeak(117);
  379.         break;
  380.     case 2:        /* trying to remove plover, bad route */
  381.         drop(EMERALD, loc);
  382.         break;
  383.     case 3:        /* troll bridge */
  384.         if (prop[TROLL] == 1)
  385.         {
  386.         pspeak(TROLL, 1);
  387.         prop[TROLL] = 0;
  388.         move(TROLL2, 0);
  389.         move((TROLL2 + MAXOBJ), 0);
  390.         move(TROLL, 117);
  391.         move((TROLL + MAXOBJ), 122);
  392.         juggle(CHASM);
  393.         newloc = loc;
  394.         }
  395.         else
  396.         {
  397.         newloc = (loc == 117 ? 122 : 117);
  398.         if (prop[TROLL] == 0)
  399.             ++prop[TROLL];
  400.         if (!toting(BEAR))
  401.             return;
  402.         rspeak(162);
  403.         prop[CHASM] = 1;
  404.         prop[TROLL] = 2;
  405.         drop(BEAR, newloc);
  406.         fixed[BEAR] = -1;
  407.         prop[BEAR] = 3;
  408.         if (prop[SPICES] < 0)
  409.             ++tally2;
  410.         oldloc2 = newloc;
  411.         death();
  412.         }
  413.         break;
  414.     default:
  415.         bug(38);
  416.     }
  417.  
  418.     return;
  419. }
  420.  
  421.  
  422. /*
  423.         Routine to handle player's demise via
  424.         waking up the dwarves...
  425. */
  426. VOID PASCAL dwarfend(VOID)
  427. {
  428.     death();
  429.     normend();            /* no return from here */
  430. }
  431.  
  432. /*
  433.         normal end of game
  434. */
  435. VOID PASCAL normend(VOID)
  436. {
  437.     score();
  438.     exit(1);
  439. }
  440.  
  441. /*
  442.         scoring
  443. */
  444. VOID PASCAL score(VOID)
  445. {
  446.     auto     SHORT    t, i, k, s;
  447.  
  448.     s = t = 0;
  449.     for (i = 50; i <= MAXTRS; ++i)
  450.     {
  451.     if (i == CHEST)
  452.         k = 14;
  453.     else
  454.         k = i > CHEST ? 16 : 12;
  455.  
  456.     if (prop[i] >= 0)
  457.         t += 2;
  458.  
  459.     if (place[i] == 3 && prop[i] == 0)
  460.         t += k - 2;
  461.     }
  462.  
  463.     printf("%-20s%d\n", "Treasures:", s = t);
  464.     t = (MAXDIE - numdie) * 10;
  465.     if (t)
  466.     printf("%-20s%d\n", "Survival:", t);
  467.     s += t;
  468.     if (!gaveup)
  469.     s += 4;
  470.     t = dflag ? 25 : 0;
  471.     if (t)
  472.     printf("%-20s%d\n"